home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / xml / XmlHttp.js < prev   
Encoding:
Text File  |  2007-04-11  |  2.8 KB  |  117 lines

  1. /****i* SOURCE_FILE/INFO
  2.     *
  3.     * NAME
  4.     *  XmlHttp.js
  5.     *
  6.     * USAGE
  7.     *  Part of Netobjects JavaScript Library.
  8.     *
  9.     * COPYRIGHT
  10.     *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.     *  All Rights Reserved.
  12.     *
  13.     *  This is an unpublished work protected by Website Pros, Inc.
  14.     *  as a trade secret, and is not to be used or disclosed except as
  15.     *  expressly provided in a written license agreement executed by
  16.     *  you and Website Pros, Inc.
  17.     *
  18.     *      <copyright@websitepros.com>
  19.     *
  20.     * NOTES
  21.     *  JavaScript code.
  22.     *
  23.     *****/
  24. if (!IS.isModuleInitialized("IS.NOF.XML.XmlHttp"))
  25. {
  26.     
  27.     /****h* NOF_JavaScript_Library/NOF.XML.XmlHttp
  28.     *
  29.     * NAME
  30.     *  NOF.XML.XmlHttp
  31.     *
  32.     * DESCRIPTION
  33.     *  
  34.     *
  35.     ****/
  36.     
  37.     /**
  38.     * Constructor    
  39.     */  
  40.     function XML_XmlHttp( ) {
  41.         this.__proto__ = XML_XmlHttp.prototype;                    
  42.     }
  43.     {
  44.         var member = XML_XmlHttp.prototype;    
  45.         
  46.         member.prefix        = null;
  47.         member.prefixes        = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
  48.         
  49.         var method = XML_XmlHttp.prototype;        
  50.         
  51.         /**
  52.         * Private method. Used to find the Automation server name
  53.         * Only for Microsoft's ActiveX.
  54.         * 
  55.         * @return 
  56.         **/                
  57.         method.getXmlHttpPrefix = function () {
  58.             if (this.prefix != null) {
  59.                 return ("" + this.prefix);
  60.             }
  61.             
  62.             var o;
  63.             for (var i = 0; i < this.prefixes.length; i++) {
  64.                 try {
  65.                     // try to create the objects
  66.                     o = new ActiveXObject(this.prefixes[i] + ".XmlHttp");
  67.                     this.prefix = this.prefixes[i];
  68.                     return ("" + this.prefix); //return this.getXmlHttpPrefix();
  69.                 } catch (ex) {
  70.                 }
  71.             }
  72.             //alert("Could not find an installed XML parser");
  73.             throw new Error("Could not find an installed XML parser");
  74.             //throw new NOF.UTIL.Exception();
  75.         }
  76.         
  77.         /**
  78.         * Creates an instance of the XmlHttp (XMLHttpRequest).
  79.         * 
  80.         * @return 
  81.         **/
  82.         method.create = function () { // document as param?
  83.             try {
  84.                 if (window.ActiveXObject) {
  85.                     return new ActiveXObject(this.getXmlHttpPrefix() + ".XmlHttp");
  86.                 }
  87.                 
  88.                 if (window.XMLHttpRequest) {
  89.                     var req = new XMLHttpRequest();
  90.                     
  91.                     // some versions of Moz do not support the readyState property
  92.                     // and the onreadystate event so we patch it!
  93.                     if (req.readyState == null) {
  94.                         req.readyState = 1;
  95.                         req.addEventListener("load", function () {
  96.                             req.readyState = 4;
  97.                             if (typeof(req.onreadystatechange) == "function") {
  98.                                 req.onreadystatechange();
  99.                             }
  100.                         }, false);
  101.                     }
  102.                     
  103.                     return req;
  104.                 }
  105.             } catch (ex) {}
  106.             // fell through
  107.             //alert("Your browser does not support XmlHttp objects");    
  108.             throw new Error("Your browser does not support XmlHttp objects");            
  109.             //throw new NOF.UTIL.Exception();
  110.         }        
  111.         
  112.     }    
  113.     
  114.     //XML.__proto__.XmlHttp = new XML_XmlHttp();
  115.     NOF.XML.__proto__.XmlHttp = new XML_XmlHttp();    
  116.     
  117. }